package dk.au.cs.peterbn.processing;

import dk.au.cs.peterbn.patterns.DesignPattern;

import javax.lang.model.element.Element;
import java.util.HashSet;
import java.util.Set;

/**
 * Internal representation of a concrete instance of a design pattern.
 *
 */
public class PatternInstance {
    private final String id;
    private final DesignPattern name;
    private final Set<Element> elements;

    /**
     * Create a new PatternInstance with an id and a name
     * @param id The id of the concrete instance
     * @param name the abstract name of the pattern
     */
    public PatternInstance(String id, DesignPattern name) {
        this.id = id;
        this.name = name;
        this.elements = new HashSet<Element>();
    }

    /**
     * @return The id of the concrete instance
     */
    public String getId() {
        return id;
    }

    /**
     * @return A name instance of the abstract pattern
     */
    public DesignPattern getName() {
        return name;
    }

    /**
     * @return A copy of the set of elements that play a role in this pattern
     */
    public Set<Element> getElements() {
        return new HashSet<Element>(elements);
    }

    /**
     * Add an element to this pattern instance
     * @param element The element to add
     * @return {@link java.util.Collection#add}
     */
    public boolean addElement(Element element) {
        return elements.add(element);
    }
}
